
using System;
using System.Collections;
using System.Web.UI.WebControls;

namespace GiftNet.Model
{
	#region StorageMap Model -(by fangyifeng at 2007-09-14 12:24:23)

	/// <summary>
	/// StorageMap object'StorageMap'.
	/// </summary>
	[Serializable]
	public class StorageMap : System.IComparable
		{
		#region Member Variables
		
		protected Guid _id;
		protected double _xCoordinate;
		protected double _yCoordinate;
		protected string _memo;
		protected City _city;
		
		protected static String _sortExpression = "Id";
		protected static SortDirection _sortDirection = SortDirection.Ascending;

		#endregion

		#region Constructors

		public StorageMap() { }

		public StorageMap( double xCoordinate, double yCoordinate, string memo, City city )
		{
			this._xCoordinate = xCoordinate;
			this._yCoordinate = yCoordinate;
			this._memo = memo;
			this._city = city;
		}

		#endregion

		#region Public Properties

		public virtual Guid Id
		{
			get {return _id;}
			set {_id = value;}
		}

		public virtual double XCoordinate
		{
			get { return _xCoordinate; }
			set { _xCoordinate = value; }
		}

		public virtual double YCoordinate
		{
			get { return _yCoordinate; }
			set { _yCoordinate = value; }
		}

		public virtual string Memo
		{
			get { return _memo; }
			set
			{
				if ( value != null && value.Length > 50)
					throw new ArgumentOutOfRangeException("Invalid value for Memo", value, value.ToString());
				_memo = value;
			}
		}

		public virtual City City
		{
			get { return _city; }
			set { _city = value; }
		}

		
        public static String SortExpression
        {
            get { return _sortExpression; }
            set { _sortExpression = value; }
        }

        public static SortDirection SortDirection
        {
            get { return _sortDirection; }
            set { _sortDirection = value; }
        }
		#endregion
		
        #region IComparable Methods
        public virtual int CompareTo(object obj)
        {
			if (!(obj is StorageMap))
				throw new InvalidCastException("This object is not of type StorageMap");
			
			int relativeValue;
			switch (SortExpression)
			{
				case "Id":
					relativeValue = this.Id.CompareTo(((StorageMap)obj).Id);
					break;
				case "XCoordinate":
					relativeValue = this.XCoordinate.CompareTo(((StorageMap)obj).XCoordinate);
					break;
				case "YCoordinate":
					relativeValue = this.YCoordinate.CompareTo(((StorageMap)obj).YCoordinate);
					break;
				case "Memo":
					relativeValue = (this.Memo != null) ? this.Memo.CompareTo(((StorageMap)obj).Memo) : -1;
					break;
                default:
                    goto case "Id";
			}
            if (StorageMap.SortDirection == SortDirection.Ascending)
				relativeValue *= -1;
			return relativeValue;
		}
		#endregion
	}

	#endregion
}
